﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FlatOut.Dal.Context;
using FlatOut.Dal.Domain;

namespace FlatOut.Services
{
    public class CircuitService
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public static List<Circuit> GetCircuits(int groupId = 0)
        {
            List<Circuit> circuits = null;

            // Find groups in base
            using (var context = new FlatOutContext())
            {
                circuits = context.Circuits.ToList();

                if (groupId > 0)
                    circuits = circuits.Where(c => c.Group.Id == groupId).ToList();
            }

            return circuits;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="circuitId"></param>
        /// <returns></returns>
        public static Circuit GetCircuit(int circuitId)
        {
            Circuit circuit;

            // Find groups in base
            using (var context = new FlatOutContext())
            {
                circuit = context.Circuits.SingleOrDefault(c => c.Id == circuitId);
            }

            return circuit;
        }
    }
}